export function formatTimeDifference(timestamp) {
    const now = Date.now(); // 获取当前时间戳
    const diff = now - timestamp; // 计算时间差，单位为毫秒

    if (diff < 0) {
        return null; // 如果时间戳是未来时间，返回 null
    }

    const oneMinute = 60 * 1000; // 一分钟的毫秒数
    const oneHour = 60 * oneMinute; // 一小时的毫秒数
    const oneDay = 24 * oneHour; // 一天的毫秒数
    const oneMonth = 30 * oneDay; // 一个约定月的毫秒数（30天）
    const threeMonths = 3 * oneMonth; // 三个月的毫秒数

    if (diff < oneMinute) {
        return "1分钟";
    } else if (diff < oneHour) {
        const minutes = Math.floor(diff / oneMinute);
        return `${minutes}分钟`;
    } else if (diff < oneDay) {
        const hours = Math.floor(diff / oneHour);
        return `${hours}小时`;
    } else if (diff < oneMonth) {
        const days = Math.floor(diff / oneDay);
        return `${days}天`;
    } else if (diff < threeMonths) {
        const months = Math.floor(diff / oneMonth);
        return `${months}月`;
    } else {
        return null;
    }
}

export function gotoHome(){
	uni.showModal({
		title:"提示",
		content:"页面有误将返回首页",
		showCancel:false,
		success:(res)=>{
			if(res.confirm){
				uni.reLaunch({
					url:"/pages/index/index"
				})
			}
		}
	})
}